package com.dongdongshop.controller;


import com.dongdongshop.data.Result;
import com.dongdongshop.service.OrderService;
import com.dongdongshop.vo.OrderVO;
import com.dongdongshop.vo.TradeVO;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private OrderService orderService;


    //增加订单
    @PostMapping("addOrder")
    public Result addOrder(@RequestHeader String AutharizeToken, @RequestParam Long addressId, @RequestParam String payType) {
        TradeVO tradeVO = orderService.addOrder(AutharizeToken, addressId, payType);
        return Result.OK().setData(tradeVO);
    }

    //修改订单信息
    @PostMapping("updateOrderStatus")
    public Result updateOrderStatus(@RequestParam String out_trade_no, @RequestParam String trade_no) {
        orderService.updateOrderStatus(out_trade_no, trade_no);
        return Result.OK();
    }

    //查询当前用户订单信息
    @PostMapping("getAllOrderByUser")
    public Result getAllOrderByUser(@RequestHeader String AutharizeToken,@RequestParam String flag){
        List<OrderVO> orderVOS =  orderService.getAllOrderByUser(AutharizeToken,flag);
        return Result.OK().setData(orderVOS);
    }

    //退款修改订单状态
    @PostMapping("refundOrderStatus")
    public Result refundOrderStatus(@RequestParam Long id) {
        orderService.refundOrderStatus(id);
        return Result.OK();
    }

    @XxlJob(value = "updateOrder")
    public void updateOrder(){
        System.out.println("修改订单状态");
        orderService.updateOrder();
    }
}
